<template>
  <el-card class="item" v-if="articleInfo">
    <div class="top-content" @click="navigateToInfo(articleInfo.id)">
      <div class="title">
        <span class="top">置顶</span>
        <h4>{{ articleInfo.title }}</h4>
        <p>
          {{ articleInfo.summary }}
        </p>
      </div>
      <div class="img">
        <img   v-lazy="articleInfo.titleImg"/>
      </div>
    </div>
    <div class="bottom-content">
      <div class="avatar">
        <img :src="articleInfo.authorInfo.avatar" alt="" />
      </div>
      <div class="name">{{ articleInfo.authorInfo.nickname }}</div>
      <div class="tooltip">
        <el-tooltip class="box-item" effect="dark" content="文章分类" placement="top" v-if="articleInfo.typeId">
          <el-tag>{{ articleInfo.typeInfo.typeName }}</el-tag>
        </el-tooltip>
        <el-tooltip class="box-item" effect="dark" content="文章标签" placement="top" v-for="item in articleInfo.tagList" :key="item.id" v-if="articleInfo.tagsId">
          <el-tag :type="tagStyle[Math.round(Math.random()*4)]">{{ item.tagName }}</el-tag>
        </el-tooltip>
      </div>

      <div class="labels">
        <span class="label"
          ><el-icon><View /></el-icon>阅读{{ zanNum }}</span
        >
        <span class="label"
          ><el-icon><ChatDotRound /></el-icon>评论{{ articleInfo.commentNum }}</span
        >
        <span class="label"
          ><el-icon><Star /></el-icon>收藏{{ collectNum }}</span
        >
        <span class="label dianzan"
          ><svg-icon name="dianzan" width="12" height="12"></svg-icon>赞{{
            zanNum
          }}</span
        >
        <span class="label"
          ><el-icon><Clock /></el-icon>{{ "3天前" }}</span
        >
      </div>
    </div>
  </el-card>
</template>
<script setup>
import {ref,computed} from "vue"
import {useRouter} from "vue-router"

const $props = defineProps({
  articleInfo: {
    type: Object,
  },
});

let zanNum = computed(() => {
  if ($props.articleInfo.dianzanIds) {
    let ids =
      $props.articleInfo.dianzanIds.split(",").filter((item) => item !== "") ||
      [];
    console.log(ids, "ids");
    return ids.length||0;
  } else {
    return 0;
  }
});
let collectNum = computed(() => {
  if ($props.articleInfo.collectIds) {
    let ids = $props.articleInfo.collectIds.split(",").filter((item) => item !== "") || [];
    console.log(ids, "collecgtids");

    return ids.length ||0;
  } else {
    return 0;
  }
});


const tagStyle = ref(["","success","danger","info","warning"]);
const router = useRouter();
const navigateToInfo = (id)=>{
    router.push({
      path:`/article/${id}`,
      
    })
}
</script>
<style lang="scss" scoped>
.item {

  cursor: pointer;
  border-radius: 5px;
  margin-bottom: 20px;
  transition: all 0.5s ease-out;
  &:hover {
    box-shadow: 1px 1px 10px 5px $shadowcolor;
  }
  .top-content {
    display: flex;
    justify-content: space-between;
    .title {
      flex: 1;
      height: 120px;
      font-size: 16px;
      p {
        width: 70%;
        margin-top: 10px;
        font-size: 0.8em;
        overflow: hidden;
        // 下面四行代码用于多行溢出
        -webkit-box-orient: vertical;
        text-overflow: ellipsis;
        -webkit-line-clamp: 2;
        display: -webkit-box;
      }
      .top {
        box-sizing: border-box;
        padding: 2px 5px;
        font-size: 12px;
        color: #fff;
        border-top-left-radius: 30%;
        border-bottom-right-radius: 30%;
        background-image: linear-gradient(0deg, orange, red);
        margin-right: 5px;
        font-size: 0.8em;
      }
      h4 {
        display: inline-block;
        background: linear-gradient(to right, red, rgba(255, 166, 0, 0.584)) no-repeat;
        background-size: 0px 2px;
        background-position: 0 bottom;  //左偏移0 上偏移20px
        transition: background-size 0.35s;
        padding-bottom: 5px;
        &:hover {
          background-size: 100% 2px;
          background-position:0 bottom;
        }
      }
    }
    .img {
      width: 180px;
      height: 110px;
      border-radius: 5%;
      overflow: hidden;

      cursor: pointer;
      img {
        border-radius: 5%;
        width: 100%;
        height: 100%;
        background: #444;
        transition: all 0.5s ease-out;
        &:hover {
          transform: scale(1.1);
        }
      }
    }
  }
  .bottom-content {
    box-sizing: border-box;
    padding: 0 10px;
    margin-top: 20px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    .avatar {
      display: flex;
      border: 1px solid pink;
      width: 40px;
      height: 40px;
      border-radius: 50%;
      margin-right: 5px;
      img {
        border-radius: 50%;
        width: 100%;
        height: 100%;
      }
    }
    .name {
      margin-right: 20px;
      color: $strong;
    }
    .tooltip {
      .el-tag {
        margin-right: 8px;
      }
    }
    .labels {
      margin-left: 10px;
      display: flex;
      flex-wrap: wrap;
      font-size: 12px;
      .label {
        display: flex;
        align-items: center;
        margin-right: 10px;
        .el-icon {
          margin-right: 5px;
        }
      }
      .dianzan {
        :deep svg {
          vertical-align: -1px;
          margin-right: 5px;
        }
      }
    }
  }
}

:deep .el-card__body {
  padding: 10px 30px 10px 15px;
}
</style>
